class ImagesController < ApplicationController
  layout nil
  
  def index
    respond_to do |format|
      format.html { 
        render 
      }
      format.json {
        images = []
        Ec2Factory.create(User.find(session[:current_user_id]), session[:url]).describe_images.each_with_index{|rawImage, i|
          p rawImage
          
          images << {:id => i + 1, :cell => [
            rawImage[:aws_id], 
            rawImage[:aws_image_type],
            rawImage[:aws_architecture],
            rawImage[:aws_platform],
            rawImage[:aws_location],
          ]}
        }
        
        render :json => {
          :page => params[:page],
          :total => images.length / params[:rows].to_i + 1,
          :records => images.length,
          :rows => images 
        }.to_json
      }
    end
  end
end
